from regen import *

if __name__ == '__main__':
    
    fluid = 'NITROGEN.FLD'              #Coolant REFPROP file
    mdot = 0.1                          #Coolant Flow Rate, kg/s
    kwall = 200.                        #Wall Conductivity, W/m/K
    Rwall = 0.00000254                  #wall roughness, m
       
    # The following parameters are specified as lists of [[X],[Y]]
    #   where X is the axial station in meters,
    #   and Y is the value of the parameter at the coresponding 
    #   axial station.
    A = [[-0.75*0.0254,0.0,1.0*0.0254,2.0*0.0254],
    [3e-5, 1.5e-5, 3.0e-5, 3.0e-5]]     #Coolant Flow Area, m^2
    D = [[-0.75*0.0254,0.0,1.0*0.0254,2.0*0.0254],
    [1.5*0.0254, 0.5*0.0254, 
        1.0*0.0254, 1.0*0.0254]]        #Chamber Diameter, m
    nC = [[-0.75*0.0254,0.0,0.0254,0.0255,2.0*0.0254],
    [24,24,24,36,36]]                      #Number of Channels
    tHot = [[-10,10],[3400,3400]]       #Hot Gas Temperature, K
    
    hconvRef = [2000,5000,1000,1000]    #Hot Gas Convection Coeff, W/m^2/K
    hconvRef = scale(hconvRef,1.,0.5)   #linear scaling function
    hconvhot = scaleH(hconvRef,100,110) #Scale by ^0.8, for Pressure
    
    hc = [[-0.75*0.0254,0.0,1.0*0.0254,2.0*0.0254],hconvhot]
                                        #Hot Side Convection Coeff

    X = [-0.75*0.0254,2.0*0.0254]       #Axial Station for Start and Stop of analysis, m
    
    
    p0 = 1000/14.7*101.353              #Coolant Inlet Pressure, kPa
    T0 = 300                            #Coolant Inlet Temperature, K
    
    npts = 50                           #number of grid points
    
    ref.SETUP(fluid)
    h0 = ref.TPFLSH(T0,p0)[5]/ref.wm.value

    start = time.clock()
    results = march_new(p0,h0,mdot,A,X,D,
            hc,tHot,nC,t0=T0,
            fluid=fluid,res=npts,kwall=kwall,k=Rwall)
    print 'run time (s)',time.clock()-start
    print 'Coolant Enthalpy Change (kJ/kg) = ',(results[1][-1]-results[1][0])
    print 'Total Heat Load (kJ/s) = ',(results[1][-1]-results[1][0])*mdot
    print 'Jacket dP (psi) = ',(results[9][0]-results[9][-1])/101353*14.7

    makePlots(results,location='example')#Writes results as .PNG
    writeResults('example/outfile.csv',results)  #writes a .csv file
    

    

    

